/**
 *******************************************************************************
 * @FileName  : tlsr825x_dma.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-09-10
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#ifndef _TLSR825X_DMA_H
#define _TLSR825X_DMA_H

#include "tlsr825x.h"

/*** DMA Channel define. ***/
#define DMA_Channel_0   0x00
#define DMA_Channel_1   0x01
#define DMA_Channel_2   0x02
#define DMA_Channel_3   0x03
#define DMA_Channel_4   0x04
#define DMA_Channel_5   0x05
#define DMA_Channel_7   0x06
#define IS_DMA_CHANNEL(CHANNEL)    (((CHANNEL) == DMA_Channel_0) || \
									((CHANNEL) == DMA_Channel_1) || \
									((CHANNEL) == DMA_Channel_2) || \
									((CHANNEL) == DMA_Channel_3) || \
									((CHANNEL) == DMA_Channel_4) || \
									((CHANNEL) == DMA_Channel_5) || \
									((CHANNEL) == DMA_Channel_7)    )

/*** DMA Interrupt bit define ***/
#define DMA_IT_Channel_0       ((uint8_t)0x01) /*!< DMA channel 0 use for UART RX.    */
#define DMA_IT_Channel_1	   ((uint8_t)0x02) /*!< DMA channel 1 use for UART TX.    */
#define DMA_IT_Channel_2       ((uint8_t)0x04) /*!< DMA channel 2 use for RF RX.      */
#define DMA_IT_Channel_3       ((uint8_t)0x08) /*!< DMA channel 3 use for RF TX.      */
#define DMA_IT_Channel_4       ((uint8_t)0x10) /*!< DMA channel 4 use for AES decrypt.*/
#define DMA_IT_Channel_5       ((uint8_t)0x20) /*!< DMA channel 5 use for AES encrypt.*/
#define DMA_IT_Channel_6       ((uint8_t)0x40) /*!< DMA channel 6 reserved.           */
#define DMA_IT_Channel_7       ((uint8_t)0x80) /*!< DMA channel 7 use for PWM0.*/

/**
 * @brief : DMA define initialization.
 * @param : None.
 * @return: None.
 */
void DMA_DefInit(void);

/**
 * @brief : DMA Channel x configuration.
 * @param : DMA_Channel     DMA channel, can be DMA_Channel_0/DMA_Channel_1...
 * @param : pBuf            Pointer point to memory.
 * @param : byteLen         the length of pBuf.
 * @return: None.
 */
void DMA_Init(uint8_t DMA_Channel, uint8_t *pBuf, uint32_t byteLen);

/**
 * @brief : DMA Channel x Interrupt configuration.
 * @param : DMA_IT          DMA Interrupt, can be DMA_IT_Channel_0/DMA_IT_Channel_1...
 * @param : enable          enable/disable DMA IT
 * @return: None.
 */
void DMA_ITConfig(uint8_t DMA_IT, bool_t enable);

/**
 * @brief : DMA Channel x enable/disable.
 * @param : DMA_Channel          DMA enable, can be DMA_Channel_0/DMA_Channel_1...
 * @param : enable               enable / disable DMA channel.
 * @return: None.
 */
void DMA_Cmd(uint8_t DMA_Channel, bool_t enable);

/**
 * @brief : Get DMA Channel x interrupt state flag.
 * @param : DMA_IT          DMA Interrupt flag, can be DMA_IT_Channel_0/DMA_IT_Channel_1...
 * @return: None.
 */
static inline uint8_t DMA_GetITFlag(uint8_t DMA_IT)
{
	return DMA->IRQ_STA & DMA_IT;
}

/**
 * @brief : Clear DMA Channel x interrupt state flag.
 * @param : DMA_IT          DMA Interrupt flag, can be DMA_IT_Channel_0/DMA_IT_Channel_1...
 * @return: None.
 */
static inline void DMA_ClearITFlag(uint8_t DMA_IT)
{
	DMA->IRQ_STA = DMA_IT;
}


/*** Assert error type ***/
#define DMA_ERR_CHANNEL      0x000A0000

#endif


